package com.bjgzy.rating.di.module;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bjgzy.rating.R;
import com.bjgzy.rating.mvp.contract.WinningWorkContract;
import com.bjgzy.rating.mvp.model.WinningWorkModel;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.EntriesData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.FragmentScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

import static com.eduhzy.ttw.commonsdk.core.Constants.AWARD;

/**
 * @author xubo
 * @date 2018-8-21 18:57:29
 */
@Module
public class WinningWorkModule {
    private WinningWorkContract.View view;

    /**
     * 构建WinningWorkModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public WinningWorkModule(WinningWorkContract.View view) {
        this.view = view;
    }

    @FragmentScope
    @Provides
    WinningWorkContract.View provideWinningWorkView() {
        return this.view;
    }

    @FragmentScope
    @Provides
    WinningWorkContract.Model provideWinningWorkModel(WinningWorkModel model) {
        return model;
    }

    @FragmentScope
    @Provides
    static List<EntriesData> provideList() {
        return new ArrayList<>();
    }

    @FragmentScope
    @Provides
    static BaseQuickAdapter<EntriesData, AutoBaseViewHolder> provideActivityAdapter(List<EntriesData> list) {
        return new BaseQuickAdapter<EntriesData, AutoBaseViewHolder>(R.layout.rating_rv_item_winning, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, EntriesData item) {
                Glide.with(helper.itemView.getContext())
                        .load(item.getImg())
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_logo));
                helper.setText(R.id.tv_title, item.getWorksName());
                helper.setText(R.id.tv_vote, item.getVoteCount() + " 票");
                helper.setText(R.id.tv_no, item.getResearchWorksNo());
                helper.setText(R.id.tv_name, item.getUnionName());
                helper.setText(R.id.tv_level, AWARD[item.getAwardLevel()]);
            }

        };
    }

    @FragmentScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManger(WinningWorkContract.View view) {
        return new GridLayoutManager(view.getActivity(), 2);
    }
}